<template>
    <div class="equipmentLayout">
        <commonHeader v-if="!fullScreen"/>
        <div id="subApplication"  :class="fullScreen ? '' : 'zy-content'" v-if="microAppsActive"></div>
          <keep-alive v-if="!microAppsActive" :include="['equipmentsLedgerPageList','productionReportingRecords','statementWorkOrder','maintenanceListPage','maintainPlanPage','MaintenanceTaskManagement']">
        <router-view/>
      </keep-alive>
    </div>
</template>

<script>
import commonHeader from '@/components/commonHeader'
import start from '@ice/stark/lib/start'
import { registerMicroApps } from '@ice/stark/lib/apps'
import { event } from '@ice/stark-data';
    export default {
        name: 'equipmentNetworkLayout',
        data() {
            return {
              microAppsActive: false,
              fullScreen: false
            }
        },
        components: {
          commonHeader
        },
        created() {
          let windowType = this.urlSearchString(this.$route.fullPath, 'windowType');
          if(windowType === 'dataBoard'){
            this.fullScreen = true
          } else {
            this.fullScreen = false
          }
        },
      mounted() {
        event.on('LogOut', () => {
          this.$router.push('/')
        });

        registerMicroApps([
          {
            name: 'saleGoodsManage',
            activePath: '/saleGoodsManage',
            container: '#subApplication',
            url: [
              '/saleGoodsManage/static/js/runtime.js',
              '/saleGoodsManage/static/js/chunk-elementUI.js',
              '/saleGoodsManage/static/js/chunk-libs.js',
              '/saleGoodsManage/static/js/app.js',
              '/saleGoodsManage/static/css/chunk-elementUI.css',
              '/saleGoodsManage/static/css/chunk-libs.css',
              '/saleGoodsManage/static/css/app.css'
            ]
          }
        ]);

        start({
          onLoadingApp: (params) => {
            console.log(params,'onLoadingApp');
          },
          onFinishLoading: (params) => {
            console.log(params,'onFinishLoading');
          },
          onRouteChange: (url, pathname) => {
            let rootId = this.urlSearchString(location.href, 'rootId');
            if(rootId){
              let oldCode = sessionStorage.getItem('isActive') ||  localStorage.getItem('isActive')
              if(oldCode && oldCode !== rootId){
                event.emit('resetStore')
              }
              localStorage.setItem('isActive', rootId)
              sessionStorage.setItem('isActive',rootId)
            }
          },
          onActiveApps: (activeApps) => {
            console.log(activeApps);
            this.microAppsActive = !!(activeApps || []).length;
          },
          shouldAssetsRemove: (url, element) => {
            return false;
          }
        });
      },
      methods: {
        urlSearchString(data, name) {
          let reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)');
          let r = data.substr(data.indexOf('?')).substr(1).match(reg);
          if (r != null) return decodeURIComponent(r[2]);
          return null;
        },
        setSessionAndLocalStorage(key, value) {
          sessionStorage.setItem(key, value);
          localStorage.setItem(key, value);
        }
      }
    }
</script>


<style lang="scss" scoped>
    .equipmentLayout{
        min-width: 1240px;
    }
</style>
